<?php
class diaocha_log extends base{

	public function init(){ // 公用
		parent::init(); // 这是必须的


		$this->tit = '记录';
		$this->companyObj = D('company');
		$this->modelObj = D('company_diaocha_log');
		$this->diaochaObj = D('company_diaocha');
		$this->adminObj = D('company_admin');
		$this->userObj = D('company_user');
		$this->bingchuangObj = D('company_bingchuang');

		$this->fankuiObj = D('company_fankui');

		$this->areaObj = D('company_area');
		$this->cateObj = D('company_cate');
		$this->zoneObj = D('company_zone');

		$this->area_list = $this->areaObj->get_TreeList("status=1 ".$this->cond_base);
		$this->cate_list = $this->cateObj->get_TreeList("status=1 ".$this->cond_base);
		$this->zone_list = $this->zoneObj->get_TreeList("status=1 ".$this->cond_base);

		$cond = "status=1".$this->cond_base;
		$this->diaochas = $this->diaochaObj->findAllByPk(array($cond),'id asc');

		$cond = "status=1 and (level>=3 and level<=6 ) ".$this->cond_base;
		$this->admin_list = $this->adminObj->get_treeList($cond,'id desc');
	}

    //列表
	public function index(){
		$this->tabtit = array('全部','非常满意','较满意','一般满意','不满意');
		$cond = "1=1".$this->cond_base;
		//加入查询条件
		switch($this->tab){
			case '1':
				$cond .=" and count_bmy=0 and status=1";
				break;
			case '2':
				// $cond .=" and count_bmy>0 and status=1";
				$cond .=" and log like '%较满意%' and status=1";
				break;
			case '3':
				$cond .=" and log like '%一般满意%' and status=1";
				break;
			case '4':
				$cond .=" and log like '%不满意%' and status=1";
				break;
			default:
				$cond .=" and status=1";
		}
		$result = $this->modelObj->get_pagelist($cond);

		if($result){
			foreach ($result['list'] as $val) {
				if($val['count_bmy']){
					$val['bmy_lv'] = round(($val['count_num']-$val['count_bmy'])/$val['count_num']*100,2);
				}else{
					$val['bmy_lv'] = "100.00";
				}
				$list[] = $val;
			}
			$this->zones = $this->zoneObj->ids($result['list'],'zone_id');
			$this->bingchuangs = $this->bingchuangObj->ids($result['list'],'bingchuang_id');
			$this->users = $this->userObj->ids($result['list'],'user_id');
			// dump($this->areas);exit;
			$this->list = $list;
			$this->showPage = $result['showPage'];
			$this->total = $result['total'];
		}

	}

	//添加
	public function add(){
		if($this->isAjax()){
			$data['company_id'] = $this->company['id'];
			$res = $this->modelObj->add($data);
			$this->renderSuccess('添加成功', "/{$this->routeUrl}/index");
		}

		$options = ['非常满意','较满意','一般满意','不满意','不了解'];
		$this->options = $options;
		$this->info = array('sort'=>100,'status'=>1);
		$this->display($this->routeUrl."/set.php");
	}

	//编辑
	public function edit(){
		$id = arg('id');
		if($this->isAjax()){

			$data = $this->postData('data');

			$options = $this->postData('options');
			$data['options'] = implode('|',$options);

			$data['company_id'] = $this->company['id'];
			$this->modelObj->edit($id,$data);
			$this->renderSuccess('编辑成功', "/{$this->routeUrl}/index");
		}
		$this->info = $this->modelObj->findById($id);
		$this->options = explode('|', $this->info['options']);
		// dump($this->info);exit;
		$this->display($this->routeUrl."/set.php");
	}

    //审核
	public function act()
	{
		$id = arg('id');
		$status = arg('status');
		$msg = ($status==1)?'显示':'隐藏';
		$opid = arg('opid');
		if($this->isAjax()){
			if($id){
				$res = $this->modelObj->act($id,$status);
				$this->renderSuccess($msg.'成功');
			}else{
				if($opid){
					foreach($opid as $val){
						$res = $this->modelObj->act($val,1);
					}
					$this->renderSuccess('显示成功');
				}else{
					$this->renderError('请选择数据');
				}
			}
		}
	}

    //删除
	public function del()
	{
		$id = arg('id');
		$opid = arg('opid');
		if($this->isAjax()){
			if($id){
				$res = $this->modelObj->del($id);
				$this->renderSuccess('删除成功');
			}else{
				if($opid){
					foreach($opid as $val){
						$res = $this->modelObj->del($val);
					}
					$this->renderSuccess('删除成功');
				}else{
					$this->renderError('请选择数据');
				}
			}

		}
	}

	//隐藏
	public function ban()
	{
		$opid = arg('opid');
		if($this->isAjax()){
			if($opid){
				foreach($opid as $val){
					$res = $this->modelObj->act($val,0);
				}
				$this->renderSuccess('隐藏成功');
			}
			$this->renderError('请选择数据');
		}
	}

	//排序
	public function sort()
	{
        $sort = arg('sort');
		$result = $this->modelObj->sort($sort);
		$this->renderSuccess('排序成功');
	}


	//编辑
	public function info(){
		$id = arg('id');
		$info = $this->modelObj->findById($id);
		if($info){

			if($info['log']){
				$logs = explode('|',$info['log']);
				$i = 1;
				foreach($logs as $val){
					$options = explode(',', $val);
					$v2['diaocha_id'] = $options[0];
					$v2['diaocha_text'] = $options[1];
					$v2['i'] = $i;



					$cond = "status=1 and diaocha_id='{$v2['diaocha_id']}' and diaocha_log_id='{$info['id']}'";
					$v2['fk_info'] = $this->fankuiObj->find(array($cond));

					$i = $i + 1;
					$list[] = $v2;
				}

				$this->list = $list;
			}



			$bingchuang = $this->bingchuangObj->findById($info['bingchuang_id']);
			$zone = $this->zoneObj->findById($bingchuang['zone_id']);
			$company = $this->companyObj->findById($bingchuang['company_id']);


			$this->info = $info;
			$this->bingchuang = $bingchuang;
			$this->zone = $zone;
			$this->company = $company;
		}
		// dump($this->info);exit;
		// $this->display($this->routeUrl."/info.php");
		$this->layout = "admin/layout2.php";
	}


	//排序
	public function qrcode1()
	{
		require(APP_DIR.'/protected/include/lib/phpqrcode.php');

        $id = arg('id');
		$status = arg('status');
		$opid = arg('opid');
		if($this->isAjax()){
			if($id){
				$url = $this->setting['site']['site_url'].'/index/diaocha/add?bc_id=='.$id;
				$info = $this->modelObj->findById($id);
				$res = $this->modelObj->qrcode($url,$info,$this->company,'bingchuang');
				$this->renderSuccess('生成二维码成功');
			}else{
				if($opid){

					foreach($opid as $val){
						$url = $this->setting['site']['site_url'].'/index/order/add?zone_id='.$val;
						$info = $this->modelObj->findById($val);
						$res = $this->modelObj->qrcode($url,$info,$this->company,'bingchuang');
					}
					$this->renderSuccess('生成二维码成功');
				}else{
					$this->renderError('请选择数据');
				}
			}
		}
	}

	//排序
	public function qrcode2()
	{
		require(APP_DIR.'/protected/include/lib/phpqrcode.php');

        $id = arg('id');
		$status = arg('status');
		$opid = arg('opid');
		if($this->isAjax()){
			if($id){


				$url = $this->setting['site']['site_url'].'/index/login/reg?zone_id='.$id;
				$info = $this->modelObj->findById($id);
				$res = $this->modelObj->qrcode($url,$info,$this->company,'reg');
				$this->renderSuccess('生成二维码成功');
			}else{
				if($opid){

					foreach($opid as $val){
						$url = $this->setting['site']['site_url'].'/index/login/reg?zone_id='.$val;
						$info = $this->modelObj->findById($val);
						$res = $this->modelObj->qrcode($url,$info,$this->company,'reg');
					}
					$this->renderSuccess('生成二维码成功');
				}else{
					$this->renderError('请选择数据');
				}
			}
		}
	}


	//排序
	public function zipdown()
	{

        $filePath = "./upload/bingchuang/{$this->company['id']}/";
		$zipFileName = "bingchuang_{$this->company['id']}.zip";

		$zip = new \lib\ZipService();
		$zip = $zip->createZip($filePath, $zipFileName);

		$file = $zipFileName;
		if (file_exists($file)) {
			header('Content-Description: File Transfer');
			header('Content-Type: application/zip');
			header('Content-Disposition: attachment; filename="'.basename($file).'"');
			header('Expires: 0');
			header('Cache-Control: must-revalidate');
			header('Pragma: public');
			header('Content-Length: ' . filesize($file));
			readfile($file);
			@unlink($file);
			exit;
		}
	}









	//导出
	public function outdata(){

		// $this->groups = D('company_group111')->fetchAll(array('status=1 and '.$this->cond),'orderby asc');
		// $this->shifu_list = D('company_admin111')->fetchAll(array('status=1 and (level=2 or level=3) and '.$this->cond),'id asc');

		 $info['time_s'] = date('Y-m-01',strtotime('-1 month'));
		 $info['time_e'] = date('Y-m-30',strtotime('-1 month'));

		 $info['time_s2'] = '';
		 $info['time_e2'] = '';
		 $info['orderstatus'] = 5;
		 $this->info = $info;

		 if($this->fmdo=='outdata'){
			 /*分类切换*/
			 $this->time_s2 = arg('time_s2');
			 $this->time_e2 = arg('time_e2');

			 $cond = 'status=1 and '.$this->typecond;

			 $this->cate_id = arg('cate_id');
			 if($this->cate_id){
				 $cond .=" and cate_id={$this->cate_id}";
			 }

			 $this->admin_id = arg('admin_id');
			 if($this->admin_id){
				 $cond .=" and admin_id={$this->admin_id}";
			 }

			 $this->shifu_id = arg('shifu_id');
			 if($this->shifu_id){
				 $cond .=" and shifu_id={$this->shifu_id}";
			 }

			 $this->shifu_id_cp = arg('shifu_id_cp');
			 if($this->shifu_id_cp){
				 $cond .=" and shifu_cp_id={$this->shifu_id_cp}";
			 }

			 $this->orderstatus = arg('orderstatus');
			 if($this->orderstatus){
				 if($this->orderstatus==5 || $this->orderstatus==6){
					 $cond .=" and orderstatus>=5";
				 }else{
					 $cond .=" and orderstatus={$this->orderstatus}";
				 }

			 }
			 //搜索
			 if($this->keyword){
				 $cond.=" and (title like '%".$this->keyword."%' or intro like '%".$this->keyword."%') ";
			 }
			 if($this->time_s){
				 $cond .=" and add_time >= '".$this->time_s." 00:00:00' ";
			 }
			 if($this->time_e){
				 $cond .=" and add_time <= '".$this->time_e." 23:59:59' ";
			 }
			 if($this->time_s2){
				 $cond .=" and up_time >= '".$this->time_s2." 00:00:00' ";
			 }
			 if($this->time_e2){
				 $cond .=" and up_time <= '".$this->time_e2." 23:59:59' ";
			 }
 // 			dump($cond);
			 $result = $this->modelObj->findAll(array($cond),'id desc');
			 if($result){
			  //   dump(count($result));exit;
				 foreach ($result as $val) {
					 if($val['shifu_id']) $shifu_ids[$val['shifu_id']] = $val['shifu_id'];
					 if($val['admin_id']) $admin_ids[$val['admin_id']] = $val['admin_id'];
					 if($val['shifu_cp_id']) $shifu_cp_ids[$val['shifu_cp_id']] = $val['shifu_cp_id'];

				 // 	if($val['orderstatus']==5 && $val['id']<39949){
	 // 				    $cond = "order_id={$val['id']} and orderstatus=5";
	 // 				    $order_log = D('company_orderlog')->find(array($cond));
	 // 				    $val['up_time'] = $order_log['add_time'];

	 // 				    if($val['admin_id']<5601){
	 // 				        $admin_name = D('company_admin111')->findById($val['admin_id']);
	 // 				        $val['admin_name'] = $admin_name['realname'];

	 // 				        $group_name = D('company_group111')->findById($val['group_id']);
	 // 				        $val['group_name'] = $group_name['name'];
	 // 				    }

	 // 				}

					 $list[] = $val;

				 }
				 if($shifu_ids){
					 $this->shifus = D('company_admin')->findByIds($shifu_ids);
					 $this->shifu_cps = D('company_admin')->findByIds($shifu_cp_ids);
				 }
				 if($admin_ids){
					 $this->admins = D('company_admin')->findByIds($admin_ids);
				 }


			 }

			 $this->list = $list;
 // 			dump($list);exit;


			 require(APP_DIR.'/protected/include/PHPExcel.php');
			 $data['examTitle'] = $this->time_s.'到'.$this->time_e.'订单统计';

			 // Create new PHPExcel object
			 $objPHPExcel = new PHPExcel();
			 // Set properties
			 $objPHPExcel->getProperties()->setCreator("ctos")
					 ->setLastModifiedBy("ctos")
					 ->setTitle("Office 2007 XLSX Test Document")
					 ->setSubject("Office 2007 XLSX Test Document")
					 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
					 ->setKeywords("office 2007 openxml php")
					 ->setCategory("Test result file");

			 // set width
			 // $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);

			 // $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(20);

			 // // 设置行高度
			 $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22);

			 $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20);

			 // // 字体和样式
			 // $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10);
			 // $objPHPExcel->getActiveSheet()->getStyle('A2:D2')->getFont()->setBold(true);
			 // $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);

			 // $objPHPExcel->getActiveSheet()->getStyle('A2:D2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			 // $objPHPExcel->getActiveSheet()->getStyle('A2:D2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);

			 // // 设置水平居中
			 // $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			 // $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			 // $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			 // $objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
			 // $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);


			 // //  合并
			 // $objPHPExcel->getActiveSheet()->mergeCells('A1:D1');
			 //
			 //
			 if($this->orderstatus==5){

				 $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
				 $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);
				 $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(40);

				 // 表头  ID	内容	选项	全院
				 $objPHPExcel->setActiveSheetIndex(0)
						 ->setCellValue('A1', '序号')
						 ->setCellValue('B1', '科室')
						 ->setCellValue('C1', '报修时间')
						 ->setCellValue('D1', '维修内容')
						 ->setCellValue('E1', '维修材料')
						 ->setCellValue('F1', '材料费')
						 ->setCellValue('G1', '人工费')
						 ->setCellValue('H1', '合计/元')
						 ->setCellValue('I1', '维修人员')
						 ->setCellValue('J1', '状态')
						 ->setCellValue('K1', '完成时间')
						 ->setCellValue('L1', '完成描述')
						 ->setCellValue('M1', '位置')
						 ->setCellValue('N1', '描述')
						 ->setCellValue('O1', '报修人');

			  //    $maxColumn = count($this->keshis) + 4;
				 // for ($i = 4; $i < $maxColumn; $i++) {
			  //        $pCoordinate = PHPExcel_Cell::stringFromColumnIndex($i) . '' . ($j + 2);
			  //        $pValue      = $keshis[$i]['name'];
			  //        $objPHPExcel->setActiveSheetIndex()->setCellValue($pCoordinate, $pValue);
				 // }
				 if($list){
					 // 内容
					 foreach($list as $key => $val) {
						 // $objPHPExcel->getActiveSheet()->getRowDimension($key + 3)->setRowHeight(42);

						 if(!$val['group_name']){
							 $val['group_name'] = $this->groups[$val['group_id']]['name'];
						 }
						 if(!$val['admin_name']){
							 $val['admin_name'] = $this->admins[$val['admin_id']]['realname'];
						 }

						 $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($key +2), $val['id']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('B'.($key +2), $val['group_name']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($key +2), $val['add_time']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('D'.($key +2), $val['title']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('E'.($key +2), $val['cailiao']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('F'.($key +2), $val['cl_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('G'.($key +2), $val['rg_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('H'.($key +2), $val['z_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('I'.($key +2), $this->shifus[$val['shifu_id']]['realname']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('J'.($key +2), $this->orderStatus[$val['orderstatus']]);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('K'.($key +2), $val['up_time']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('L'.($key +2), $val['wc_intro']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('M'.($key +2), $val['local']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('N'.($key +2), $val['intro']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('O'.($key +2), $val['admin_name']);
					  //    foreach($val['options'] as $v) {
					  //    	$options .= $v."\r\n";
						 // }
						 // $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($key +3), $options);
						 // unset($options);
					  //    foreach($val['quan_bfbs'] as $v) {
					  //    	$quan_bfbs .= $v."%\r\n";
						 // }
						 // $objPHPExcel->getActiveSheet(0)->setCellValue('D'.($key +3), $quan_bfbs);
						 // unset($quan_bfbs);




						 $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':D' . ($i + 3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
						 $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':D' . ($i + 3))->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
						 $objPHPExcel->getActiveSheet()->getRowDimension($i + 3)->setRowHeight(16);
					 }

				 }


			 }else{



				 // 表头  ID	内容	选项	全院
				 $objPHPExcel->setActiveSheetIndex(0)
						 ->setCellValue('A1', $data['examTitle'])
						 ->setCellValue('A2', 'ID')
						 ->setCellValue('B2', '分类')
						 ->setCellValue('C2', '科室')
						 ->setCellValue('D2', '报修员')
						 ->setCellValue('E2', '维修员')
						 ->setCellValue('F2', '标题')
						 ->setCellValue('G2', '位置')
						 ->setCellValue('H2', '备注')
						 ->setCellValue('I2', '时间')
						 ->setCellValue('J2', '订单状态')
						 ->setCellValue('K2', '评价')
						 ->setCellValue('L2', '材料')
						 ->setCellValue('M2', '材料费')
						 ->setCellValue('N2', '人工费')
						 ->setCellValue('O2', '总发费')
						 ->setCellValue('P2', '设备型号')
						 ->setCellValue('Q2', '重派员')
						 ->setCellValue('R2', '更新时间')
						 ->setCellValue('S2', '完成描述');

			  //    $maxColumn = count($this->keshis) + 4;
				 // for ($i = 4; $i < $maxColumn; $i++) {
			  //        $pCoordinate = PHPExcel_Cell::stringFromColumnIndex($i) . '' . ($j + 2);
			  //        $pValue      = $keshis[$i]['name'];
			  //        $objPHPExcel->setActiveSheetIndex()->setCellValue($pCoordinate, $pValue);
				 // }
				 if($list){
				 // 内容
					 foreach($list as $key => $val) {
						 // $objPHPExcel->getActiveSheet()->getRowDimension($key + 3)->setRowHeight(42);

						 $objPHPExcel->getActiveSheet(0)->setCellValue('A'.($key +3), $val['id']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('B'.($key +3), $this->cates[$val['cate_id']]['name']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($key +3), $this->groups[$val['group_id']]['name']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('D'.($key +3), $this->admins[$val['admin_id']]['realname']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('E'.($key +3), $this->shifus[$val['shifu_id']]['realname']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('F'.($key +3), $val['title']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('G'.($key +3), $val['local']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('H'.($key +3), $val['intro']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('I'.($key +3), $val['add_time']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('J'.($key +3), $this->orderStatus[$val['orderstatus']]);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('K'.($key +3), $val['star_info']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('L'.($key +3), $val['cailiao']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('M'.($key +3), $val['cl_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('N'.($key +3), $val['rg_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('O'.($key +3), $val['z_money']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('P'.($key +3), $val['shebei']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('Q'.($key +3), $this->shifu_cps[$val['shifu_cp_id']]['realname']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('R'.($key +3), $val['up_time']);
						 $objPHPExcel->getActiveSheet(0)->setCellValue('S'.($key +3), $val['wc_intro']);
					  //    foreach($val['options'] as $v) {
					  //    	$options .= $v."\r\n";
						 // }
						 // $objPHPExcel->getActiveSheet(0)->setCellValue('C'.($key +3), $options);
						 // unset($options);
					  //    foreach($val['quan_bfbs'] as $v) {
					  //    	$quan_bfbs .= $v."%\r\n";
						 // }
						 // $objPHPExcel->getActiveSheet(0)->setCellValue('D'.($key +3), $quan_bfbs);
						 // unset($quan_bfbs);




						 $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':D' . ($i + 3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
						 $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':D' . ($i + 3))->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
						 $objPHPExcel->getActiveSheet()->getRowDimension($i + 3)->setRowHeight(16);
					 }
				 }
			 }

			 // Rename sheet
			 $objPHPExcel->getActiveSheet()->setTitle($data['examTitle']);

			 // Set active sheet index to the first sheet, so Excel opens this as the first sheet
			 $objPHPExcel->setActiveSheetIndex(0);



			 // 输出
			 header('Content-Type: application/vnd.ms-excel');
			 header('Content-Disposition: attachment;filename="' . $data['examTitle'] . '.xls"');
			 header('Cache-Control: max-age=0');

			 $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
			 $objWriter->save('php://output');



		 }
	}

	//导出
	public function export(){
		// $id = arg('id');
		// if($this->isAjax()){
		// 	$cond = "status=1".$this->cond_base;

		// 	$data = $this->postData('data');

		// 	$result = $this->orderObj->exportList($cond,$data);

		// 	$this->renderSuccess('导出成功');
		// }
		// $this->info = $this->orderObj->findById($id);

		$info['time_s'] = date('Y-m-01',strtotime('-1 month'));
		$info['time_e'] = date('Y-m-30',strtotime('-1 month'));

		$info['time_s2'] = '';
		$info['time_e2'] = '';
		$info['orderStatus'] = 5;
		// $info['admin_id'] = 100;
		$this->info = $info;

		$this->layout = "admin/layout2.php";
	}

	//导出
	public function export_csv(){

		$data = $this->postData('data');

		$cond = "status=1".$this->cond_base;
		if($data['order_status']){
			switch($data['order_status']){
				case '8':
					$cond .=" and order_status=99";
					break;
				default:
					$cond .=" and order_status={$data['order_status']}";
			}
		}
		if($data['keyword']){
			$cond .=" and (title like '%".$data['keyword']."%') ";
		}

		$result = $this->orderObj->exportList($cond,$data);

	}


	//导出
	public function outdata_myd(){
		// $id = arg('id');
		// if($this->isAjax()){
		// 	$cond = "status=1".$this->cond_base;

		// 	$data = $this->postData('data');

		// 	$result = $this->orderObj->exportList($cond,$data);

		// 	$this->renderSuccess('导出成功');
		// }
		// $this->info = $this->orderObj->findById($id);

		$info['time_s'] = date('Y-m-01',strtotime('-1 month'));
		$info['time_e'] = date('Y-m-30',strtotime('-1 month'));

		$info['time_s2'] = '';
		$info['time_e2'] = '';
		$info['orderStatus'] = 5;
		// $info['admin_id'] = 100;
		$this->info = $info;

		// $this->layout = "admin/layout2.php";
	}

	//导出
	public function outdata_myd_csv(){

		$data = $this->postData('data');

		// 获取当前科室
        $zones = $this->zoneObj->findAll(array('status=1 and parent_id>0 '.$this->cond_base),'sort asc,tag asc,id asc');

		// $cond = "status=1".$this->cond_base;
		// if($data['order_status']){
		// 	switch($data['order_status']){
		// 		case '8':
		// 			$cond .=" and order_status=99";
		// 			break;
		// 		default:
		// 			$cond .=" and order_status={$data['order_status']}";
		// 	}
		// }
		// if($data['keyword']){
		// 	$cond .=" and (title like '%".$data['keyword']."%') ";
		// }

		$result = $this->modelObj->outdata_myd_csv($zones,$data);

	}
}